package com.seleniti.enpareja.web.desktop.client.ui.view;

import org.ioc.commons.impl.gwt.client.ui.ViewComposite;
import org.ioc.commons.ui.HasValue;
import org.ioc.commons.ui.impl.HasValueAdapter;
import org.ioc.commons.ui.impl.OnChangeCommand;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.seleniti.enpareja.controller.ui.view.RequiredReloadPresenter;
import com.seleniti.enpareja.controller.ui.view.RequiredReloadView;
import com.seleniti.enpareja.controller.ui.view.RequiredReloadView.Action;
import com.seleniti.enpareja.controller.ui.view.RequiredReloadView.Event;
import com.seleniti.enpareja.controller.ui.view.RequiredReloadView.Operation;
import com.seleniti.enpareja.controller.ui.view.RequiredReloadView.Presenter;

public class RequiredReloadViewWidget extends EnParejaBaseView<Event, Operation, Action, Presenter> implements RequiredReloadView {

	private static RequiredReloadViewWidgetUiBinder uiBinder = GWT.create(RequiredReloadViewWidgetUiBinder.class);

	interface RequiredReloadViewWidgetUiBinder extends UiBinder<Widget, RequiredReloadViewWidget> {
	}
	
	@UiField
	Label lblCounter;

	public RequiredReloadViewWidget() {
		this.presenter = new RequiredReloadPresenter(this, eventbus, operationManager, actionController);
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@UiHandler("btnReloadNow")
	void onLetsStartButtonClicked(ClickEvent evt) {
		this.presenter.onReloadNow();
	}

	@Override
	public HasValue<Integer> counter() {
		return HasValueAdapter.<Integer>forField("couneter", this).onChange(new OnChangeCommand<Integer>() {
			
			@Override
			public void execute(Integer value) {
				lblCounter.setText(value != null ? value.toString() : null);
			}
		});
	}

}
